<?php

/**
 * Created by PhpStorm.
 * Author: kaodou
 * Date: 2018/3/1
 * Time: 14:13
 */
namespace App\Http\Admin\Address\Controllers;

use App\Eloquent\Area;
use App\Eloquent\City;
use App\Eloquent\Province;

class IndexController
{
    public function ajaxAreaList()
    {
        $type               = request('type',1);
        $value              = request('value',0);
        switch ($type)
        {
            case 1:
                $data       = Province::get()->toArray();
                break;
            case 2:
                $where      = ['fatherID'=>$value];
                $data       = City::where($where)->get();
                $data       = $data->map(function($item){
                    return [
                        $item->cityID,
                        $item->city,
                    ];
                })->toArray();
                array_unshift($data,['','请选择城市']);
                break;
            case 3:
                $where      = ['fatherID'=>$value];
                $data       = Area::where($where)->get();
                $data       = $data->map(function($item){
                    return [
                        $item->areaID,
                        $item->area,
                    ];
                })->toArray();
                array_unshift($data,['','请选择地区']);
                break;
            default:
                $data       =[];
        }
        $result             = json_encode($data);
        return $result;
    }
}